<%@taglib prefix="s" uri="/struts-tags" %>
<%@page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>

<head>
    <title><s:text name="search.results"/></title>   
</head>

<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/search.css"/>

<script>
	function navigateToPage(i) {
		document.forms['navigationSearch'].page.value = i;
		document.forms['navigationSearch'].submit();
	}
</script>
   
<s:if test="totalPages == 0">
	<s:text name="search.noresults"/>
</s:if>
<s:else>
	<form id="navigationSearch" action="Search" method="get">
		<s:hidden id="name" name="name"/>
		<s:hidden id="page" name="page"/>
		<s:hidden id="marketGroupId" name="marketGroupId"/>
		<s:hidden id="groupId" name="groupId"/>
		
		<!-- Breadcrumbs (Market Groups) -->
		<s:if test="marketGroupId != null">
			<div class="breadCrumbs">
				<s:set var="parents" value="marketGroupParents"/>
				<s:if test="marketGroup != null"><a href="SearchMarketGroups"><s:text name="market.groups"/></a> ></s:if>
				<s:iterator value="parents" var="current" end="0" begin="#parents.size - 1" step="-1">
					<a href="SearchMarketGroups?id=${current.id}">${current.name}</a> >  
				</s:iterator>
				<span class="current">${marketGroup.name}</span>
			</div>		
		</s:if>
		
		<!-- Breadcrumbs (Categories/Groups) -->
		<s:if test="groupId != null">
			<div class="breadCrumbs">
				<a href="Categories"><s:text name="categories"/></a> >
				<a href="Groups?categoryId=${group.category.id}">${group.category.name}</a> >
				<span class="current">${group.name}</span>
			</div>	
		</s:if>
		
		<!-- Pages navigation buttons -->
		<s:if test="startPage != endPage">
			<s:if test="startPage > 1">
				<span class="navigateButton" onclick="navigateToPage(1)">1</span>
			</s:if>
			
			<s:if test="startPage > 2">...</s:if>
			
			<s:iterator value="navigationPages" var="i">
				<span class="${(i==page)?'currentButton':'navigateButton'}" onclick="navigateToPage(${i})">${i}</span>
			</s:iterator>
			
			<s:if test="endPage < (totalPages - 1)">...</s:if>
			
			<s:if test="endPage < totalPages">
				<span class="navigateButton" onclick="navigateToPage(${totalPages})">${totalPages}</span>
			</s:if>
		</s:if>
		
		<!-- Total -->
		<!-- span class="total"><s:text name="search.total"/>: ${totalRows}</span-->
		
		<!-- Main part (results table) -->
		<table id="resultsTable" class="completelyBordered">
			<s:iterator value="results" var="item" status="rowStatus">
				<tr>
					<td class="imgCell img32Cell ${rowStatus.odd ? 'oddRow' : 'evenRow'}" style="background-image: url(${pageContext.request.contextPath}/img/Types/${item.id}_32.png)"></td>
					<td class="nameCell ${rowStatus.odd ? 'oddRow' : 'evenRow'}"><a href="DisplayItemInfo?id=${item.id}">${item.name}</a></td>
				</tr>
			</s:iterator>
		</table>
		
		<!-- Pages navigation buttons again-->
		<s:if test="startPage != endPage">
			<s:if test="startPage > 1">
				<span class="navigateButton" onclick="navigateToPage(1)">1</span>
			</s:if>
			
			<s:if test="startPage > 2">...</s:if>
			
			<s:iterator value="navigationPages" var="i">
				<span class="${(i==page)?'currentButton':'navigateButton'}" onclick="navigateToPage(${i})">${i}</span>
			</s:iterator>
			
			<s:if test="endPage < (totalPages - 1)">...</s:if>
			
			<s:if test="endPage < totalPages">
				<span class="navigateButton" onclick="navigateToPage(${totalPages})">${totalPages}</span>
			</s:if>
		</s:if>
		
		<!-- span class="total"><s:text name="search.total"/>: ${totalRows}</span-->
	</form>
</s:else>
